<template>
  <t-dialog :header="header" :visible.sync="visible" :onClose="closeDialog" :closeOnOverlayClick="false"
    :confirmBtn="null" width="90%" top="5%">
    <div style="height: 60vh">
      <PlatformMyDetail :header="header" :objId="objId"></PlatformMyDetail>
    </div>

  </t-dialog>
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'

import PlatformMyDetail from "./platform-my-detail.vue";


export default {

  components: {
    PlatformMyDetail,
  },
  props: {
    objId: [String, Number],
    header: String,
    isDialog: {
      type: Boolean,
      default: true
    },
    hideInfo: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      reviewOpen: false,
      profTitOptions: [],
      deptMenuOptions: [],
      stepTwoData: null,
      stepThreeData: null,
      stepFourData: null,
      stepFiveData: null,
      file_domain: VITE_FILE_DOMAIN,

      site_tag: import.meta.env.VITE_SITE_TAG,
      visible: true,
      currentDeptName: '',
      tabValue: "1",
      data: {
        name: "",
        platformCategory: "",
        address: "",
        postCode: "",
        buildDate: "",
        website: "",
        content: "",
        platformLeader: {
          name: "",
          sex: "",
          birthDate: "",
          education: "",
          duty: "",
          profTitId: "",
          profTit: "",
          majorName: "",
          telephone: "",
          phone: "",
          email: "",
        },
        platformLinker: {
          name: "",
          telephone: "",
          phone: "",
          email: "",
          facsimile: "",
        },
        constructionUnit: {
          name: "",
          sex: "",
          birthDate: "",
          education: "",
          duty: "",
          profTitId: "",
          profTit: "",
          majorName: "",
          telephone: "",
          phone: "",
          email: "",
          deptName: "",
          deptTelephone: "",
          deptFacsimile: "",
          deptAddress: "",
          deptPostCode: "",
        },

        platformBackground: {
          background: ""
        },
        platformMainTask: {
          mainTask: ""
        },
        platformBudget: {

        },
        platformEquipments: {

        },
        platformSafeguard: {

        }
      },
      projectCategoryOptions: []
    }
  },
  watch: {
    objId: {
      immediate: true,
      handler (val) {
        if (val) {
        }
      }
    },
  },
  methods: {
    getProfTitTreeSelect () {
      return this.$api.system.profTit.list().then(response => {
        this.profTitOptions = this.handleTree(response.data, "id");
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getDeptTreeSelect () {
      return this.$api.system.dept.treeSelectAllIn().then(response => {
        this.deptMenuOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getUserInfo () {
      this.$api.system.user.getBaseInfo().then(response => {
        this.currentDeptName = response.data.dept.deptName;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    async getObj () {
      // await Promise.all([this.getDeclareTree()]);
      try {
        let allDetail1 = await this.$api.kjpt.project.getAll(this.objId)
        // let member1 = await this.$api.kjpt.project.getPlatformMemberByType(this.objId, "1")
        // let member2 = await this.$api.kjpt.project.getPlatformMemberByType(this.objId, "2")
        // let allDetail2 = await this.$api.kjpt.project.getSafeguardByPlatformId(this.objId)
        getFiles(this.objId).then((res) => {
          const files = {}
          res.data.forEach((item) => {
            if (!files[item.moduleKey]) {
              files[item.moduleKey] = []
            }
            files[item.moduleKey].push({
              name: item.fileName,
              url: item.fullFilePath,
              id: item.id,
              filePath: item.filePath
            })
          })
          this.projectFileData.forEach((val, index) => {
            this.projectFileData[index].fileLists = files[val.moduleKey] || [];
            this.projectFileData[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
          })
          // this.projectFileData[0].fileLists = files.kjptsysryb || [];
          // this.projectFileData[0].fileIds = files.kjptsysryb?.map(val => val.id) || [];

          // this.projectFileData[1].fileLists = files.kjptzjfa || [];
          // this.projectFileData[1].fileIds = files.kjptzjfa?.map(val => val.id) || [];

          // this.projectFileData[2].fileLists = files.kjpthzxy || [];
          // this.projectFileData[2].fileIds = files.kjpthzxy?.map(val => val.id) || [];

          // this.projectFileData[3].fileLists = files.kjptqtdwjctj || [];
          // this.projectFileData[3].fileIds = files.kjptqtdwjctj?.map(val => val.id) || [];

          // this.projectFileData[4].fileLists = files.kjptqt || [];
          // this.projectFileData[4].fileIds = files.kjptqt?.map(val => val.id) || [];
          console.log('------', this.projectFileData);

        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });
        Object.assign(this.data, allDetail1.data)
        // this.data.member1 = member1.data
        // this.data.member2 = member2.data
        // this.data.platformSafeguard.background = allDetail2.data?.safeguardCondition
        // console.log("allDetail2", allDetail2)
        console.log('this.data', this.data)
      } catch (e) {
        this.$message.error(e.toString());
      }

    },
    getStepData () {
      this.$api.kjpt.project.getPlatformMemberNoType(this.objId).then(response => {
        this.stepTwoData = response.data
      }).catch((e) => {
        this.$message.error(e.toString());
      });

      this.$api.kjpt.project.getByPlatformId(this.objId).then(response => {
        this.stepThreeData = response.data
      }).catch((e) => {
        this.$message.error(e.toString());
      });

      this.$api.kjpt.project.getManageOrgByPlatformId(this.objId).then(response => {
        this.stepFourData = response.data
      }).catch((e) => {
        this.$message.error(e.toString());
      });

      this.$api.kjpt.project.getManageScienceByPlatformId(this.objId).then(response => {
        this.stepFiveData = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getDeclareTree () {
      return this.$api.kjxm.project.planCategoryTree().then(response => {
        this.projectCategoryOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    closeDialog () {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style lang="less" scoped>
.t-tab-panel {
  padding: 10px;
  height: 100%;
}

.t-form__item {
  margin-bottom: 6px
}

.t-row {
  margin-bottom: 14px;
}

.step-card {
  height: 100%;
  margin-bottom: 14px;
}

.content_style {
  font-size: 12pt;
  font-family: 宋体;
  line-height: 1.5;
}

.t-tab-panel {
  padding: 10px;
}

.tab-panel {
  height: calc(65vh - 64px);
  overflow: scroll;
}

.tab-full-panel {
  height: calc(80vh - 64px);
  overflow: scroll;
}
</style>
